<?php
/**
 * 涂原料管理模型
 * 
 * @author  Lee<a605333742@gmail.com>
 * @time    2016-07-31
 */
namespace Model;
use Think\Model;

class MaterialModel extends Model{
    /*
     * 涂原料编辑
     * 
     * @return bool
     */
    public function edit($where){
        $g='';
        if($where['id']){
            //id存在为修改
            if($this->save($where)){
                $g="修改";
            }else{
                return FALSE;
            }
        }else{
            //否则为新增
            $where['add_time']  =time();
            if($this->add($where)){
                $g="新增";
            }else{
                return FALSE;
            }
        }
        $data=array(
            'user_id'   =>session("authId"),
            'content'   =>$g.'了名为 '.$where['name'].' 的涂原料',
            'add_time'  =>time()
        );
        if(M("Log")->add($data)){
            return TRUE;
        }else{
            return FALSE;
        }
    }
    
    /*
     * 删除。批量删除涂原料
     * 
     * @return bool
     */
    public function del($where){  
        $g  =$where['id'];
        if(is_array($where['id'])){
            $g  =implode(',',$where['id']);
            $where['id']=array("in",implode(',',$where['id']));            
        }
        if($this->where($where)->delete()){
            $data=array(
                'user_id'   =>session("authId"),
                'content'   =>'删除了id为 '.$where['id'].' 的涂原料',
                'add_time'  =>time()
            );
            M("Log")->add($data);
            return TRUE;
        }else{
            return FALSE;
        }
    }
}